﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class userControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            Label showadduser = (Label)FindControl("showadduser");

            if (_EluZSDataProvider.IsZSAdmin(userid) || _EluZSDataProvider.IsNetZSAdmin(userid))
            {
                showadduser.Visible = true;
                Page.ClientScript.RegisterStartupScript(this.GetType(), "showspan", "<script>showspan();</script>");
            }
            else {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "shwotable", "<script>shwotable();</script>");
            }
           // if (!base.Page.IsPostBack)
            //{
                Bind();
           // }
            Button tosearch = (Button)FindControl("tosearch");
            tosearch.Click += new EventHandler(tosearch_Click);
        }
        protected void Bind()
        {
            MPRepeater MPRepeaterList = (MPRepeater)FindControl("MPRepeaterList");
            TextBox userlname = (TextBox)FindControl("userlname");
            string strwhere = "";
            if (!_EluZSDataProvider.IsZSAdmin(userid) && !_EluZSDataProvider.IsNetZSAdmin(userid))
            {
                strwhere = " and id='" + userid + "' ";
            }
            if (!string.IsNullOrEmpty(userlname.Text))
            {
                strwhere += " and (name like '%" + userlname.Text.Trim() + "%' or loginid like '%" + userlname.Text.Trim() + "%') ";
            }
            MPRepeaterList.ItemDataBound += new RepeaterItemEventHandler(MPRepeaterList_ItemDataBound);
            DataTable dt = _EluZSDataProvider.GetUserAll(strwhere);
            MPRepeaterList.DataSource = dt;
            MPRepeaterList.DataBind();
        }
        protected void MPRepeaterList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Label showdel = (Label)e.Item.FindControl("showdel");
            if (!_EluZSDataProvider.IsZSAdmin(userid) && !_EluZSDataProvider.IsNetZSAdmin(userid))
            {
                showdel.Visible = false;
            }
        }
        protected void tosearch_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}


